public class MethodDecl
{
	public DataInfo dataInfo;
	public String methodType;
	public String methodName;
	private FormalParams formalParams;
	private Block block;

	public MethodDecl( String mn, String type, FormalParams fp, Block block, DataInfo dataInfo )
	{
		methodName = mn;
		methodType = type;
		formalParams = fp;
		this.block = block;
		this.dataInfo = dataInfo;

	}

	public String toString()
	{
		String tobeReturned = "";

		tobeReturned += "MethodDecl " + this.methodName + "\n";

		if( formalParams != null )
			tobeReturned += "| " + formalParams;

		tobeReturned += "| " + block;

		String result = "";
		for( String s : tobeReturned.split( "\n" ) )
		{
			result += "| " + s + "\n";
		}
		return result;

	}

	public void check() throws SemanticException
	{

		SymbolTable st = SymbolTable.getInstance();

		if( formalParams != null )
			st.get( methodName ).methodParameters = formalParams.getParamTypes();

		st.openScope();

		if( formalParams != null )
			formalParams.check();

		block.methodName = methodName;

		block.check();

		if( !block.willReturn() )
		{
			String details = "Method " + methodName + " does not have a reachable return statement.";
			if( dataInfo != null )
				throw new SemanticException( dataInfo.lineNumber, dataInfo.charNumber, dataInfo.line, details );
			else
				throw new SemanticException( details );
		}

		st.closeScope();// before closing must check that there is a return
						// statement...................

	}

}